package tree.递归.剑指;

import po.TreeNode;

/**
 * @author songZiHao
 * @version 1.0.0
 * @ClassName 剑指Offer对称的二叉树28.java
 * @Description TODO https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof/
 * @createTime 2021年03月28日 10:53:00
 */
public class 剑指Offer对称的二叉树28 {
    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        }
        return judge(root.left, root.right);
    }

    private boolean judge(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        }
        if (left == null || right == null) {
            return false;
        }
        return right.val == left.val && judge(left.right, right.left) && judge(left.left, right.right);
    }
}
